# @Time    : 2019/8/26 16:51
# @Author  : patrick
# @File    : excute.py
# @Software: PyCharm
import datetime

from common.common import readPremiumTable, writePremiumReuslt
from service.premiumService import getHttpResult, getDBResult


def excute_test():
    result = readPremiumTable("Premium_Test_Data.xlsx")
    # actual_premium = list()
    # expect_premium = list()
    # 定义结果文件名
    now = datetime.datetime.now().strftime('%Y-%m-%d_%H-%M-%S')
    filename = "Premium_Test_Result_%s.xls" % now
    for i in range(0, result.__len__()):
        # 调用接口请求并返回结果
        actual_premium = getHttpResult(salesProductCode=result[i][0], coverage=str(result[i][1]), sex=result[i][2],
                                       age=result[i][3],
                                       hasSecurity=result[i][4], paymentPeriod=result[i][5], paymentMethod=result[i][6],
                                       occupationCode=result[i][7])
        print(actual_premium)
        # 调用数据库请求并返回结果
        expect_premium = getDBResult(salesProductCode=result[i][0], coverage=str(result[i][1]), sex=result[i][2],
                                     age=result[i][3],
                                     hasSecurity=result[i][4], paymentPeriod=result[i][5], occupationCode=result[i][7])
        print(expect_premium)
        # 将结果写入excel
        writePremiumReuslt(
            filename=filename,
            excepctList=expect_premium,
            actualList=actual_premium,
            salesProductCode=result[i][0],
            coverage=str(result[i][1]),
            sex=result[i][2],
            age=result[i][3],
            hasSecurity=result[i][4],
            paymentPeriod=result[i][5],
            paymentMethod=result[i][6],
            occupationCode=result[i][7]
        )
        print("-----------------------------------------")


if __name__ == '__main__':
    excute_test()
